package veterinaria.servlets;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import veterinaria.modelo.Persona;
import veterinaria.negocio.GestionCliente;

/**
 * Servlet implementation class ClienteIngresoServlet
 */
@WebServlet("/ClienteIngresoServlet")
public class ClienteIngresoServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ClienteIngresoServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
        String pEst = "Cliente";
        String pNom = request.getParameter("txtPerNombre");
        String pDom = request.getParameter("txtPerDomicilio");       
        String pTel = request.getParameter("txtPerTelefono");       
        String pCel = request.getParameter("txtPerCelular");
        String pCor = request.getParameter("txtPerCorreo");
        String pIma = request.getParameter("txtPerImagen");
        String pRuc = request.getParameter("txtCliRuc");
        try {
        	Persona cPer = new Persona();
        	cPer.setPerNombre(pNom);
        	cPer.setPerDomicilio(pDom);
        	cPer.setPerTelefono(pTel);
        	cPer.setPerCelular(pCel);
        	cPer.setPerCorreo(pCor);
        	cPer.setPerImagen(pIma);
            GestionCliente negocio = new GestionCliente();
            negocio.insertar(pEst,pRuc,cPer);
            request.setAttribute("aCliente", negocio.buscarPorNombre(pEst,pNom));
            RequestDispatcher rd = request.getRequestDispatcher("ClienteIngreso.jsp");
            rd.forward(request, response);
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }			
	}
}